package edu.towson.cosc.cosc455.brandonmoodyProject1;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

//public class Token {
/**
 * The Token set as an Enum type. This is just "binds" each token to its list of
 * valid lexemes.
 *
 * @author Adam J. Conover
 */
public enum Token {
    DOCUMENT("Document", "DOCUMENT", "document"),
    HEAD("HEAD", "Head", "head"),
    TITLE("TITLE","Title", "title"),
    PARAGRAPH("PARAGRAPH", "Paragraph", "paragraph"),
    BOLD("BOLD", "bold", "Bold"),
    ITALICS("ITALICS", "italics", "Italics"),
    LIST("LIST","List", "list"),
    ITEM("ITEM","item","Item"),
    EMPTY(""),
    NEWLINE("#NEWLINE"),
    AUDIO("AUDIO","audio","Audio"),
    VIDEO("VIDEO","video","Video"),
    DEFINE("DEFINE","Define","define"),
    USE("USE","use","Use"),
    TERMINAL_START("#START"),
    TERMINAL_END("#END"),
    BODY("BODY","body","Body"),
    NAME("NAME","name","Name"),
    VALUE("VALUE","value","Value"),
    EOF("\n"),
    ID(),
  //TEXT token is missing quotes("")
    TEXT("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
    	"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
    	"0","1","2","3","4","5","6","7","8","9",
    	",",".",":","?","!","%","\t","\n","/","'"); 
    
    // List of all possible allowed lexemes token can be
    private List<String> lexemeList;

    // Construct the token with the list of allowed lexemes
    private Token(String... tokenStrings) {
        lexemeList = new ArrayList<>(tokenStrings.length);
        lexemeList.addAll(Arrays.asList(tokenStrings));
    }

    // Gets a token from a lexeme
    public static Token fromLexeme(String str) {
        // Search through the lexemes looking for a match.
        for (Token t : Token.values()) {
            if (t.lexemeList.contains(str)) {
                return t;
            }
        }
     
        try{
            Integer.parseInt(str);
            return TEXT;
        } 
        catch(NumberFormatException nfe){
            return ID;
        }
    }
}